import type { Plugin } from "@vuepress/core";
import { path } from "@vuepress/utils";

export interface BaiduAnalyticOptions {
    /**
     * Baidu hm code
     */
    hm: string;

    /**
     * Whether ignore local URL
     */
    ignoreLocal: boolean;
}


export const baiduAnalyticPlugin = (options: BaiduAnalyticOptions): Plugin =>
    (app) => {
        if (options.hm) {
            console.info("Baidu Analytic Enabled");
        }
        return {
            name: "baidu-analytic",

            define: {
                __BAIDU_ANALYTICS_OPTIONS__: options,
            },

            clientConfigFile: path.resolve(__dirname, './baidu-analytic-client.ts'),
        }
    }